import logging
import functools
import time

# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def log_time(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        start_time = time.time()  # 记录开始时间
        result = func(*args, **kwargs)  # 调用原函数
        end_time = time.time()  # 记录结束时间
        elapsed_time = end_time - start_time  # 计算运行时间
        logging.info(f"Function {func.__name__} took {elapsed_time:.4f} seconds to run.")
        return result
    
    return wrapper

def log_args(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        # 记录函数调用参数
        logging.info(f"Function {func.__name__} called with args: {args}, kwargs: {kwargs}")
        
        # 调用原函数
        result = func(*args, **kwargs)
        
        return result
    
    return wrapper

@log_time
@log_args
def display(*args, **kwargs):
    # 遍历并记录位置参数
    for arg in args:
        logging.info(arg)
    time.sleep(1)  # 模拟耗时操作
    # 遍历并记录关键字参数
    for key, value in kwargs.items():
        logging.info(f"key: {key}: value: {value}")

if __name__ == "__main__":
    my_list = [1, 2, 3]
    info = {"name": "Alice", "age": 25, "score": 85}
    # display("nihao", my_list, info)
    display(1, 2, 3, name="ceagle", score=90)